<?php

declare(strict_types=1);

namespace App\Game\Core;

/**
 * 解包，压缩包处理逻辑.
 */
class Packet
{
    /**
     * 格式化事件数据.
     */
    public static function event($event, $code = 0, $data = [],$message="成功")
    {
        return [
            'event' => $event,
            'message' => $message,
            'event_code' => $code,
            'event_uuid' => uniqid(),
            'event_time' => time(),
            'data' => $data,
        ];
    }

    /**
     * 解包数据.
     * @param mixed $str
     */
    public static function packDecode($str)
    {
        $data = json_decode($str,true);
        return $data;
    }
    
    /**
     * 解包数据.
     * @param mixed $data
     */
    public static function packEncode($data)
    {
        $str = json_encode($data,JSON_UNESCAPED_UNICODE);
        return $str;
    }
}
